---
description: "Reference for Nitric's Go library - Get a download url for a file from a bucket."
---

# Go - Bucket.DownloadUrl()

<Note>
  This is reference documentation for the Nitric Go SDK. To learn about Storage
  and Buckets in Nitric start with the [Storage docs](/storage).
</Note>

Create a download url for a file within a bucket.

```go
import (
  "context"

  "github.com/nitrictech/go-sdk/nitric"
  "github.com/nitrictech/go-sdk/nitric/storage"
)

func main() {
  bucket := nitric.NewBucket("bucket-name").Allow(storage.BucketRead)

  downloadUrl, err := bucket.DownloadUrl(context.TODO(), "cat.png")
  if err != nil {
    return
  }

  nitric.Run()
}
```

## Parameters

<Properties>
  <Property name="ctx" required type="context">
    The context of the call, used for tracing.
  </Property>
  <Property name="key" required type="string">
    The key of the file to create a download url for.
  </Property>
  <Property name="...opts" required type="storage.PresignUrlOption">
    Options to configure the download url.
  </Property>
</Properties>

## Examples

### Create a readable link that is valid for the next 5 minutes

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
  "github.com/nitrictech/go-sdk/nitric/storage"
)

func main() {
  bucket := nitric.NewBucket("bucket-name").Allow(nitric.BucketRead)

  downloadUrl, err := bucket.File("cat.png").DownloadUrl(context.TODO(), "cat.png", storage.WithPresignUrlExpiry(time.Minute*5))
  if err != nil {
    return
  }

  nitric.Run()
}
```

### Redirect response to an image URL

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric/apis"
  "github.com/nitrictech/go-sdk/nitric"
)

func main() {
  api := nitric.NewApi("main")

  bucket := nitric.NewBucket("images").Allow(nitric.BucketRead)

  api.Get("/images/:id", func(ctx *apis.Ctx) {
    id := ctx.Request.PathParams()["id"]

    downloadUrl, err := bucket.DownloadUrl(context.TODO(), id)
    if err != nil {
      return ctx, err
    }

    ctx.Response.Headers["Location"] = []string{downloadUrl}
    ctx.Response.Status = 303
  })

  nitric.Run()
}
```
